/*
 * BestTry_Main.cpp
 *
 *  Created on: Dec 20, 2014
 *      Author: marc
 */
//============================================================================
// Name        : BestTry.cpp
// Author      : Marc Petroff
// Version     :
// Copyright   : MPRights (2014)
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
#include <cstdlib>
#include <iostream>
#include <cstdarg>
//#include <regex>   // This support is currently experimental, and must be enabled with the -std=c++0x or -std=gnu++0x compiler options
#include <stdlib.h>
#include <stdio.h>
#include <memory.h>
//#include <dlfcn>
/**
 * House keeping:
 * Look for FUNCTION CORE ACTION in functions ; the comments will direct you to the essential step(s)
 *
 */
/** @define
 *  Sections where CONTROL_INSTRUCTIONS_FOR_DELETION are tested will be removed before production delivery
 */
//#define CONTROL_INSTRUCTIONS_FOR_DELETION
#undef CONTROL_INSTRUCTIONS_FOR_DELETION
#undef MP_CRYPTLIB_INTERNAL_DECLARATION
//#include "mp_crypt.h"
#undef VAL_ARGS_ENABLED
enum mp_crypt_error {
	MP_CRYPTERR_NO_ERR = 1,                    //!< MP_CRYPTERR_NO_ERR
	MP_CRYPTERR_EMPTY_PUBLIC_STRING = -8892,   //!< MP_CRYPTERR_EMPTY_PUBLIC_STRING
	MP_CRYPTERR_TOO_LONG_PUBLIC_STRING = -8893,//!< MP_CRYPTERR_TOO_LONG_PUBLIC_STRING
	MP_CRYPTERR_LIBRARY_DEPENDANCY_FAIL = -8894//!< MP_CRYPTERR_LIBRARY_DEPENDANCY_FAIL
} e;
struct peoi_html_placeholder_struct {
	char *PEOI_HTML_PLACEHOLDER_FORMNAME; //!< %FORMNAME%
	char *PEOI_HTML_PLACEHOLDER_DIVNAME; //!< "%DIVNAME%"
} html_placeholder {"%FORMNAME%","%DIVNAME%"};
struct peoi_html_token_struct {
	char *PEOI_HTML_TOKEN_SEPARATOR; //!< %/,/%
	char *PEOI_HTML_TOKEN_ENDLINE; //!< %/$/%   (similar to Regexp end of line symbol)
	char *PEOI_HTML_SSCANF_TEMPLATE_SEPARATOR; //!< %/=/%
	char *PEOI_HTML_TOKEN_DELIMITER_CUSTOM_SEP; //!< (space) string
	char PEOI_HTML_CHAR_TOKEN_DELIMITER_CUSTOM_SEP; //!< (space) character byte
	char *PEOI_HTML_TOKEN_TARGET_STREAM; //!< %/@/%  the text to the left indicates the target contents (file name?)
} html_token_separator {"%/,/%","%/$/%","%/=/%"," ",' ',"%/@/%"};
struct trackchain_struct {
	char *trackMessage;
	trackchain_struct *child;
} ;
struct hash_struct {
	char *hash;
	int length;
};
struct key_struct {
	char *key;
	int order;
};
struct key_hash_struct {
	key_struct keyvalue;
	hash_struct hashvalue;
	key_hash_struct *nextkey;
	key_hash_struct *prevkey;
};
int peoi_key_value_pair_extract(char *key,char *value,char *separator,char *delimit_custom_separator,char *in_line);
FILE *peoi_load_textfile(char *name,unsigned int maxlineread, unsigned int seekoffset, char *fopen_type) ;
int peoi_readline(char **line, char *name,unsigned int maxreadlength,FILE *f);
int peoi_key_value_extract_using_trailing_token (char *key,char *value,char **separator,char *in_line,int maxlinesize);
int peoi_index_of_last_char_separator(char*in_line,char separator);
/**
 * La variable globale qui contient le code erreur basé sur l'enum
 */
mp_crypt_error mp_errno;
int peoi_test_key_value_extract_using_trailing_token(char *key,char *value,char **separator,char *in_line,int maxlinesize) {
	int success = 0;
	int inxofsep = 0;
	char *tempcopy_in_line;
	char *tempkey;
	char *tempvalue;
	char tempseparator[25];
	char *bllop = "  THRY DOING THING, DUMMY";
	tempcopy_in_line = (char *)malloc(((strlen(in_line)  + 1) * sizeof(char)));
	tempkey = (char *)malloc((strlen(in_line)  + 1) * sizeof(char));
	tempvalue = (char *)malloc((strlen(in_line) + 1) * sizeof(char));
	tempkey[0] = '\0';
	tempvalue[0] = '\0';
	strcpy(tempcopy_in_line,in_line);
	//strcpy(tempcopy_in_line,bllop);
	printf("\n in peoi_test_key_value_extract_using_trailing_token FIRST IN_LINE %s at %x is size %i",in_line,in_line,strlen(in_line));
	printf("\n in peoi_test_key_value_extract_using_trailing_token TEMP COPY %s at %x is size %i",tempcopy_in_line,tempcopy_in_line,strlen(tempcopy_in_line));
	// extract the custom separator for the line.It may be empty
	//inxofsep = peoi_index_of_last_char_separator(tempcopy_in_line,html_token_separator.PEOI_HTML_CHAR_TOKEN_DELIMITER_CUSTOM_SEP);
	//inxofsep = peoi_index_of_last_char_separator(bllop,html_token_separator.PEOI_HTML_CHAR_TOKEN_DELIMITER_CUSTOM_SEP);
	inxofsep = peoi_index_of_last_char_separator(in_line,html_token_separator.PEOI_HTML_CHAR_TOKEN_DELIMITER_CUSTOM_SEP);
	tempcopy_in_line [inxofsep - 1] = '\0';
	strcpy(value,tempcopy_in_line + (inxofsep * sizeof(char)) + (0 * sizeof(char)));
	strcpy(key,tempcopy_in_line);
	printf("\n in peoi_test_key_value_extract_using_trailing_token %s is size %i",key,strlen(key));
	printf("\n in peoi_test_key_value_extract_using_trailing_token %s is size %i",value,strlen(value));
	printf("\n in peoi_test_key_value_extract_using_trailing_token %s is size %i",*separator,strlen(*separator));
	printf("\n in peoi_test_key_value_extract_using_trailing_token  IN_LINE %s is size %i",in_line,strlen(in_line));
	printf("\n in peoi_test_key_value_extract_using_trailing_token    SEPARATOR INDEX %i",inxofsep);
	if (tempcopy_in_line) free(tempcopy_in_line);
	if (tempvalue) free(tempvalue);
	if (tempkey) free(tempkey);
	return 1;
}
char *peoi_test_readlin(char **line,FILE *handle){
	char *y[1];
	y[0] =  (char *)malloc((1024 +1)  * sizeof(char));
	fgets(y[0],1024,handle);
	strcpy(line[0],y[0]);
	if( y[0]) free( y[0]);
	return line[0];
}
int peoi_test_iseof(FILE *handle){
	return feof(handle);
}
trackchain_struct *peoi_malloc(trackchain_struct *ptr,size_t maxsize) {
	ptr = (trackchain_struct *)malloc(maxsize);
	printf("\n in peoi_malloc MALLOCED %i for ptr %x",maxsize,ptr);
	if (ptr == NULL) {
		return (trackchain_struct *)ptr;
	}
	else {
		return (trackchain_struct *)ptr;
	}
}
trackchain_struct **peoi_malloc(trackchain_struct **ptr,size_t maxsize) {
	ptr = (trackchain_struct **)malloc(maxsize);
	printf("\n in peoi_malloc MALLOCED %i for ptr %x",maxsize,ptr);
	if (ptr == NULL) {
		return (trackchain_struct **)ptr;
	}
	else {
		return (trackchain_struct **)ptr;
	}
}
char *peoi_malloc(char *ptr,size_t maxsize) {
	ptr = (char *)malloc(maxsize);
	printf("\n in peoi_malloc MALLOCED %i for ptr %x",maxsize,ptr);
	if (ptr == NULL) {
		return (char *)ptr;
	}
	else {
		return (char *)ptr;
	}
}
int peoi_malloc_trackstruct (trackchain_struct **track,size_t maxstrsize,trackchain_struct *nexttrack) {
	int parentexists = 0;
	int messageexists = 0;
	trackchain_struct *mytrack;
	if(track) {

		if ((mytrack = (trackchain_struct *)peoi_malloc(mytrack,sizeof(trackchain_struct))) != NULL) {

			printf("\n in peoi_malloc_trackstruct MALLOCED to create parent %x",mytrack );

			parentexists++;
		}
		else {

			// unable to create a parent struct

			printf("\n in peoi_malloc_trackstruct FAILED to create parent");
		}
	}
	else {
		printf("\n in peoi_malloc_trackstruct Parent exists");
		parentexists++;
	}
	if (parentexists) {
		if ((mytrack->trackMessage = (char *)peoi_malloc(mytrack->trackMessage,maxstrsize * sizeof(char))) != NULL) {
			strcat(mytrack->trackMessage,"CHLID MESAGE of ****");

			printf("\n in peoi_malloc_trackstruct allocated message %x containing %s", mytrack->trackMessage,mytrack->trackMessage );
			messageexists++;
		}
		else {
			//  unable to create the message member
		}
	}
	else {
		return 0;
	}
	if (messageexists) {
		//if (mytrack->child = (trackchain_struct *)peoi_malloc(mytrack->child,sizeof(trackchain_struct))) {
		if (*track) {
#ifdef CONTROL_INSTRUCTIONS_FOR_DELETION
			/* anything in this _FOR_DELETION section will be removed automatically by cleaner*/
			printf("\n in peoi_malloc_trackstruct allocated Child");
#endif //CONTROL_INSTRUCTIONS_FOR_DELEND
			mytrack->child = *track;
			nexttrack  = mytrack->child;
#ifdef CONTROL_INSTRUCTIONS_FOR_DELETION
			/* anything in this _FOR_DELETION section will be removed automatically by cleaner*/
			printf("\n in peoi_malloc_trackstruct gave Child %x to outgoing vari %x",mytrack->child,nexttrack);
#endif //CONTROL_INSTRUCTIONS_FOR_DEL END

			*track = mytrack;
			//track[0]->child = mytrack;
			/*
if (track[0]->trackMessage != NULL) {
track[0]->child = mytrack;
strcpy(track[0]->trackMessage,"HEAD");
}
else {
track[0] = mytrack;
}*/
#ifdef CONTROL_INSTRUCTIONS_FOR_DELETION
			/* anything in this _FOR_DELETION section will be removed automatically by cleaner*/
			printf("\n in peoi_malloc_trackstruct ASSIGNED temp  %x to outgoing track %x",mytrack,*track);
#endif //CONTROL_INSTRUCTIONS_FOR_DEL END

			return 1;
		}
		else {
			return 0;
		}
	}
}
int peoi_sprintf(char *strbuffer,const char *stemplate,unsigned int max,...) {
	int sprintf_ret = 0;
	char *kkze[7];
	//va_list copy;
	if (strlen(strbuffer) +1 < max) {
		va_list args;
		//va_copy(copy,args);
		// TODO remove tracking instruction
		//printf("Using PRINTF %s/\n %s/\n %s/\n %s/\n %s/\n %s/\n %s/\n",args);
		//va_start(args,max);
#ifdef CONTROL_INSTRUCTIONS_FOR_DELETION
		/* anything in this _FOR_DELETION section will be removed automatically by cleaner*/
		// TODO  remove the entire for below ; it is control
		for (int i = 0; i < 7; ++i) {
			kkze[i] = (char *)malloc(256);
			strcpy(kkze[i],(const char*)va_arg(args,char **));
			printf("%s \n",kkze[i]);
		}
		std::cout << " in peoi_sprintf "<< strbuffer << " with " << stemplate << " for max " << max << " with args " << kkze[0] << kkze[4] << " end args" << std::endl;
#else
#endif //CONTROL_INSTRUCTIONS_FOR_DEL END
		//            sprintf            commande standard
		//sprintf_ret = sprintf(strbuffer,stemplate,args);
		//va_end(args);
	}
	else {   //  if (strlen(

		//   ECHEC  racourcir la chaine et préparer valeur retour 0
		strbuffer[0] = '\0';
		sprintf_ret = 0;
	} //  if (strlen(
	return sprintf_ret;
}
int peoi_track_add_log(trackchain_struct *chaintrack,char *loglinestr, unsigned int maxloglinesize) {
	int z = 0;
	trackchain_struct *tracklink;
	tracklink = (trackchain_struct *)malloc(sizeof(trackchain_struct));
	tracklink->trackMessage
	= (char *)malloc(maxloglinesize + 1);
	tracklink->child = (trackchain_struct *)malloc(sizeof(trackchain_struct));
	/*   FUNCTION CORE ACTION           ***********          the string is appended to a new link   *****************  */
	strcpy (tracklink->trackMessage,loglinestr);
	tracklink->child = 0;
	/*   FUNCTION CORE ACTION           ***********        The link is chained to the parent link   *****************  */
	// link the new set of strings to the previous end of the chain
	chaintrack->child = tracklink;
	// replace the old pointer withthe new structures' pointer
	chaintrack = tracklink;
	return 1;
}
int peoi_output_log_to_chosen_display (trackchain_struct *headchaintrack) {
	return 1;
}
int peoi_populate_token_replacement_member(char *member,char *filter,char *separator,char *key,char *value, char *custom_separator, int maxlinesize) {
	char *curcombo = (char *)malloc(2 * maxlinesize * sizeof(char));
	//Empty the string
	strcpy(member,"");
	strcat(curcombo,filter);
	strcat(curcombo,separator);
	strcat(curcombo,key);
	strcat(curcombo,separator);
	strcat(curcombo,value);
	strcat(curcombo,custom_separator);
	strcpy(member,curcombo);
	free(curcombo);
	return 1;
}
int peoi_populate_token_replacement_array(char **array_of_str) {
	const char *name = "peoi_substitution txt";
	FILE *substitutionfile;
	char *curline[1];
	char *key[1];
	char *value[1];
	char *sprat[1];
	int i = 0;
	char *stream = "%s['%/,/%']%s";
	char *cursep[1];
	cursep[0] = (char *)malloc((1024 + 1) * sizeof(char));
	strcpy(cursep[0],html_token_separator.PEOI_HTML_TOKEN_SEPARATOR);
	curline[0] = (char *)malloc((1024 + 1) * sizeof(char));
	substitutionfile = peoi_load_textfile((char *)name,(256) * sizeof(char),0,"r") ;
	int l = 0;
	if (substitutionfile != NULL) {
		while (!peoi_test_iseof(substitutionfile) && (array_of_str[l] != NULL)) {

			peoi_test_readlin(curline,substitutionfile);

			printf(" in peoi_populate_token_replacement_array  on iteration %i the curline is %s",l,curline[0]);

			key[0] = peoi_malloc(key[0],(256) * sizeof(char));

			value[0] = peoi_malloc(value[0],(256) * sizeof(char));
			//peoi_key_value_extract_using_trailing_token(member1[0],member1[1]," ",trysscanf,256

			strcpy(key[0],"");

			strcpy(value[0],"");

			if (key[0] != NULL && value[0] != NULL) {


				//  FIXME ; URGENT_1 (dependssince 1 dec 2014 the line below is failing even though the same function workes elsewhere


				printf("\n verge of calling peoi_test_key_value_extract_using_trailing_token %s is size %i",key[0],strlen(key[0]));


				printf("\n verge of calling  peoi_test_key_value_extract_using_trailing_token %s is size %i",value[0],strlen(value[0]));


				printf("\n verge of calling  peoi_test_key_value_extract_using_trailing_token %s is size %i",cursep[0],strlen(cursep[0]));


				printf("\n verge of calling  peoi_test_key_value_extract_using_trailing_token %s is size %i",curline[0],strlen(curline[0]));


				/*if (peoi_key_value_extract_using_trailing_token(key[0],value[0],&cursep[0],curline[0],(256) * sizeof(char))) {


  strcpy(array_of_str[l],key[0]);


}*/
				//  FIXME ; URGENT_3 (dependant on URGENT_2 (I think) -----   This is causing failure


				if (strlen(curline[0]) >2) {


					if (peoi_test_key_value_extract_using_trailing_token(key[0],value[0],&cursep[0],curline[0],(256) * sizeof(char))) {


					}

				}

			}

			strcpy(array_of_str[l],curline[0]);

			l++;
		}
		//strcpy(array_of_str[0],"Wild and crazy");
	}
	if( curline[0]) free( curline[0]);
	/*
if (substitutionfile) {
//  TODO read lines
// FIXME replace hard-code
curline[0] = peoi_malloc(*curline,(1024) * sizeof(char));
if (curline[0] != NULL) {
while (!feof(substitutionfile)) {
//
peoi_readline(curline,name,256,substitutionfile);

peoi_test_readlin(curline,substitutionfile);

key[0] = peoi_malloc(key[0],(256) * sizeof(char));

value[0] = peoi_malloc(value[0],(256) * sizeof(char));

if (key[0] != NULL && value[0] != NULL) {

if (peoi_key_value_extract_using_trailing_token(key[0],value[0]," ",curline[0],(256) * sizeof(char))) {

  strcpy(array_of_str[i],key[0]);

  i++;

}

}
}
}*/
	/*
peoi_populate_token_replacement_member((char *)array_of_str[i],stream,cursep,key,"myTestDivName"," /%,%/",256);
i++;
strcpy(key,html_placeholder
PEOI_HTML_PLACEHOLDER_FORMNAME);
peoi_populate_token_replacement_member((char *)array_of_str[i],stream,cursep,key,"myTestFormName"," /%,%/",256);
i++;*/
	/*
strcpy((char *)array_of_str[i]," **  END OF LIST **");
i = 0;
}
#ifdef CONTROL_INSTRUCTIONS_FOR_DELETION
 anything in this _FOR_DELETION section will be removed automatically by cleaner
while (strcmp(array_of_str[i]," **  END OF LIST **")) {
printf(" iterate %i : in peoi_populate_token_replacement_array looking  %s \n", 1+i, array_of_str[i]);
i++;
}
#endif //CONTROL_INSTRUCTIONS_FOR_DEL END
	 */
	return 1;
}
int peoi_index_of_last_char_separator(char*in_line,char separator) {
	int linelen;
	int curpos = 0;
	int stoploop = 2000;
	char *ptr_loc;
	char *new_ptr;
	ptr_loc = (char *)malloc((strlen(in_line) + 1) * sizeof(char)) ;
	strcpy(ptr_loc,in_line);
	linelen = strlen(in_line);
	//  starting spaces (or other delim) and trailing spaces are stripped out
	new_ptr = ptr_loc;
	while(!strcmp(new_ptr,strchr(new_ptr,' ')) && curpos < linelen) {
		//ptr_loc++; // move the pointer to ignore the leading space
		new_ptr++;
		curpos++;
		printf("\n in peoi_index_of_last_char_separator searching %s", (char *)(ptr_loc + curpos));
	}
	//  TODO  handle trailing spaces
	/*while (ptr_loc[linelen] == ' ') {
ptr_loc[linelen] = '\0';
linelen = strlen(ptr_loc);
}*/
	new_ptr = ptr_loc;
	ptr_loc = ptr_loc + (curpos * sizeof (char));
	// FIXME ; URGENT_2 (URGENT_1 is dependant on this) since 7 dec 2014 ; finding the index is causing error
	if (strchr((ptr_loc),separator)) {
		while ((new_ptr = strchr(ptr_loc,separator)) && curpos < linelen) {
			/*   FUNCTION CORE ACTION           **** The the pointer to the found character becomes the pointer to the string ******  */
			curpos = curpos  + (( (int)new_ptr - (int )ptr_loc ) / sizeof(char))+ (1 * sizeof (char));
			printf("\n  ALT in peoi_index_of_last_char_separator searching %s", (char *)(in_line + (curpos * sizeof(char))));
			ptr_loc = new_ptr + (1 * sizeof (char));
			stoploop--;
			if (stoploop == 0) {

				return 0;
			}
		}
	}
	if (linelen > curpos + 1) {
		return curpos;
	}
	else {
		return 0;
	}
}
int peoi_track_flush_log(trackchain_struct *headchaintrack,char *loglinestr) {
	int z = 0;
	size_t limittaille;
	size_t linesize;
	int maxloglinesize = 256;
	trackchain_struct *curchaintrack;
	curchaintrack = (trackchain_struct *)malloc(sizeof(trackchain_struct));
	// iterate through the chain to get the information out, then free all teh links
	limittaille = strlen(loglinestr);
	linesize = strlen(headchaintrack->trackMessage);
	curchaintrack = headchaintrack->child;
	z = limittaille;
	while (curchaintrack->child != NULL  && z < limittaille) {
		linesize = strlen(curchaintrack->trackMessage);
		z = z + linesize;
		/*   FUNCTION CORE ACTION           **** The chain contents is concatenated together for return ******  */
		strcat(loglinestr,curchaintrack->trackMessage);
		curchaintrack = curchaintrack->child;
	}
	trackchain_struct *tracklink;
	tracklink = (trackchain_struct *)malloc(sizeof(trackchain_struct));
	tracklink->trackMessage = (char *)malloc(maxloglinesize + 1);
	tracklink->child = (trackchain_struct *)malloc(sizeof(trackchain_struct));
	strcpy (tracklink->trackMessage,loglinestr);
	tracklink->child = 0;
	// TODO  verify the choivce of struct
	// link the new set of strings to the previous end of the chain
	headchaintrack->child = tracklink;
	// replace the old pointer withthe new structures' pointer
	headchaintrack = tracklink;
	free(curchaintrack);
	return 1;
}
int peoi_readline(char **line, char *name,unsigned int maxreadlength,FILE *f)
{int cc,h,i,j,k,v,vv,z,maxtrackline;
unsigned int x;
char *value[1];
char *track[1];
cc=h=i=j=k=v=vv=0;
z = 0;
maxtrackline = 256;
track[z] = (char *)malloc((maxtrackline + 1) * sizeof(char));
value[z] = (char *)malloc((maxreadlength + 1) * sizeof(char));
strcpy(value[z]," *******  MASSIVE FAILURE ****");
track[z][0] = '\0';
if(peoi_test_iseof(f)) {

	//if the file is at the end of file then we set the output string to null string

	value[z][0] = '\0';
}
// FUNCTION CORE ACTION           ***********          Line is read here   *****************
//     else if(!fgets(value[z],maxreadlength,f)) {
else if(peoi_test_readlin(value,f) == NULL) {

	j=k=v=vv=0;


	// peoi_sprintf(track[z],"<BR>Empty line because at end of file; name=%i/\n",maxtrackline,name);


	value[z][0] = '\0';

}
else {
	if((j=strlen(value[z]))>maxreadlength){

		// peoi_sprintf(track[z],"<BR>line too long j=%i u=%i value=%i <BR>=\n",maxtrackline,j,u,value[z]);
		// k=0;while(k<100){peoi_sprintf(track[z],"%d/",maxtrackline,value[z][k]);k++;}
		//  peoi_sprintf(track[z],"<BR>",maxtrackline,u);
	}
#ifdef CONTROL_INSTRUCTIONS_FOR_DELETION
	//anything in this _FOR_DELETION section will be removed automatically by cleaner
#ifdef VAL_ARGS_ENABLED
	//peoi_sprintf(track[z],"<BR> Still going strong;%i name=%s/\n",maxtrackline,name);
#else
	//sprintf(track[z],"<BR>Still going strong; name=%s/\n",name);
#endif
#endif //CONTROL_INSTRUCTIONS_FOR_DEL END
}
strcpy(line[0],value[z]);
// return the trace chain via the argument
//    trace = &headofchaintrack;
if( value) free( value);
if( track) free( track);
return(j);
}
int peoi_key_value_extract_using_trailing_token (char *key,char *value,char **separator,char *in_line,int maxlinesize)
{
	int success = 0;
	int inxofsep = 0;
	char *tempcopy_in_line;
	char *tempkey;
	char *tempvalue;
	char tempseparator[25];
	tempcopy_in_line = (char *)malloc(((strlen(in_line)  + 1) * sizeof(char)));
	tempkey = (char *)malloc((strlen(in_line)  + 1) * sizeof(char));
	tempvalue = (char *)malloc((strlen(in_line) + 1) * sizeof(char));
	strcpy(tempcopy_in_line,in_line);
	// extract the custom separator for the line.It may be empty
	inxofsep = peoi_index_of_last_char_separator(tempcopy_in_line,html_token_separator.PEOI_HTML_CHAR_TOKEN_DELIMITER_CUSTOM_SEP);
	// the format of the line expected is :
	if(inxofsep != 0) {

		strcpy(tempseparator,(char *)(tempcopy_in_line + (inxofsep * sizeof(char)) ));

	}
	else {

		// if we could not determine the custom separator (might be omitted in the source text line)

		// then use the separator whihc came into the function as argument

		strcpy(tempseparator,*separator);
	}
	// shear off the separator from the input line (so the separator is not returned with the value)
	if (tempcopy_in_line) free(tempcopy_in_line);
	tempcopy_in_line = (char *)malloc((strlen(in_line)   + 1) * sizeof(char));

	strncpy(tempcopy_in_line,in_line,inxofsep);
	tempcopy_in_line[inxofsep] = '\0';
#ifdef CONTROL_INSTRUCTIONS_FOR_DELETION
	/* anything in this _FOR_DELETION section will be removed automatically by cleaner*/
	printf("\n>>>>>> in peoi_key_value_extract_using_trailing_token INDEX was  %i and SEP %s while IN_LINE was %s <\n",inxofsep,tempseparator,tempcopy_in_line);
#endif //CONTROL_INSTRUCTIONS_FOR_DEL END

	if (tempcopy_in_line != NULL && key != NULL && value != NULL && separator != NULL) {
		/*   FUNCTION CORE ACTION           **** temp keyand value are extracted by strtok ******  */
		//  deconstruct the incoming line so to get the keyvalue pair and the separator
		if( peoi_key_value_pair_extract(tempkey,tempvalue," ",tempseparator,tempcopy_in_line) ) {
			// success
		}
		if (tempkey && tempvalue) {
			strcpy(key,tempkey);
			strcpy(value,tempvalue);
			success++;
		}
		else {
			strcpy(key,"DEFAULT_KEY");
			strcpy(value,"DEFAULT_VALUE");
		}
	}
	if (tempcopy_in_line) free(tempcopy_in_line);
	if (tempvalue) free(tempvalue);
	if (tempkey) free(tempkey);
	return success;
}
char *peoi_static(char *in_line) {
	static char joule[80];
	static int countt = 0;
	char *lo;
	lo = (char *)malloc(8000);
	countt = countt + strlen(in_line) + 1;
	if (countt < 80){
		strcat(joule,in_line);
		strcpy(lo,joule);
		return lo;
	}
	else {
		free(lo);
		return "OVERLOAD";
	}
}
char *peoi_strtok(char *in_line,char *token) {
	char splittoken[25];
	char cur_partial_token[25];
	char *in_line_cur_head;
	char *in_line_cur_tail;
	static char final_line_cur_head[8000];
	static char final_line_cur_tail[8000];
	char *return_line_cur_head;
	char *cur_line_position;
	char *tempcopy_in_line;
	long cur_offset;
	static int original_in_line_length;
	int tokenlen;
	// TODO reduce the overhead of duplicate instructions
	if (in_line != NULL){
		original_in_line_length = strlen(in_line);
		tokenlen = strlen(token);
		tempcopy_in_line = (char *)malloc((original_in_line_length * sizeof(char)) + 1);
		in_line_cur_head = (char *)malloc((original_in_line_length * sizeof(char)) + 1);
		in_line_cur_tail = (char *)malloc((original_in_line_length * sizeof(char)) + 1);
		return_line_cur_head = (char *)malloc((original_in_line_length * sizeof(char)) + 1);
		strcpy(tempcopy_in_line,in_line);
		cur_offset = 0;
		if ((cur_line_position = strstr(tempcopy_in_line,token)) != NULL) {
			cur_offset = ((long )cur_line_position - (long )tempcopy_in_line);
			strncpy(in_line_cur_head,tempcopy_in_line,cur_offset);
			//in_line_cur_head[cur_offset] = '"';
			in_line_cur_head[cur_offset] = '\0';
			strcpy(in_line_cur_tail, strstr(tempcopy_in_line,token));
			strcpy(in_line_cur_tail,in_line_cur_tail + (tokenlen * sizeof(char)));
		}
		else {

			//strcpy(in_line_cur_tail, "");
			strcpy(in_line_cur_head, tempcopy_in_line);
			//strcpy(in_line_cur_head, "NOT FOUND");
			//in_line_cur_tail[0] = '\0';
		}
		strcpy(final_line_cur_head,in_line_cur_head);
		strcpy(final_line_cur_tail,in_line_cur_tail);
		strcpy(return_line_cur_head,final_line_cur_head);
		return return_line_cur_head;
	}
	else {
		tokenlen = strlen(token);
		tempcopy_in_line = (char *)malloc((original_in_line_length * sizeof(char)) + 1);
		in_line_cur_head = (char *)malloc((original_in_line_length * sizeof(char)) + 1);
		in_line_cur_tail = (char *)malloc((original_in_line_length * sizeof(char)) + 1);
		return_line_cur_head = (char *)malloc((original_in_line_length * sizeof(char)) + 1);
		printf( "\n >>>>> in peoi_strtok final tail is %s \n",final_line_cur_tail );
		strcpy(tempcopy_in_line,final_line_cur_tail);
		if (final_line_cur_tail[0] != '\0') {
			cur_offset = 0;
			if ((cur_line_position = strstr(tempcopy_in_line,token)) != NULL) {

				cur_offset = ((long )cur_line_position - (long )tempcopy_in_line);

				strncpy(in_line_cur_head,tempcopy_in_line,cur_offset);

				//in_line_cur_head[cur_offset] = '"';

				in_line_cur_head[cur_offset] = '\0';

				strcpy(in_line_cur_tail, strstr(tempcopy_in_line,token));

				strcpy(in_line_cur_tail,in_line_cur_tail + (tokenlen * sizeof(char)));

			}
			else {

				//strcpy(in_line_cur_tail, "");

				strcpy(in_line_cur_head, tempcopy_in_line);

				//in_line_cur_tail[0] = '\0';

				//strcpy(in_line_cur_head, "NOT FOUND");

			}
			strcpy(final_line_cur_head,in_line_cur_head);
			strcpy(final_line_cur_tail,in_line_cur_tail);
			//strcpy(return_line_cur_head,final_line_cur_tail);
			strcpy(return_line_cur_head,final_line_cur_head);
			return return_line_cur_head;
		}
		else {

			return "BOTCHED IT";
		}
		//tempcopy_in_line = (char *)malloc((strlen(in_line) * sizeof(char)) + 1);
		//return final_line_cur_tail;
	}
	tokenlen = strlen(token);

	if (tokenlen > 1) {
		cur_offset = 0;
		if ((cur_line_position = strstr(tempcopy_in_line,token)) != NULL) {

			cur_offset = ((long )cur_line_position - (long )tempcopy_in_line);

			strncpy(in_line_cur_head,in_line,cur_offset);

			//in_line_cur_head[cur_offset] = '"';

			in_line_cur_head[cur_offset] = '\0';

			strcpy(in_line_cur_tail, strstr(tempcopy_in_line,token));

			strcpy(in_line_cur_tail,in_line_cur_tail + (tokenlen * sizeof(char)));

		}
		else {

			//strcpy(in_line_cur_tail, "");

			strcpy(in_line_cur_head, tempcopy_in_line);

			in_line_cur_tail[0] = '\0';

		}

		strcpy(final_line_cur_head,in_line_cur_head);
		strcpy(final_line_cur_tail,in_line_cur_tail);
	}
	else {
		strcpy(splittoken,token);
		strcpy(tempcopy_in_line,in_line);

		strcpy(in_line_cur_head,in_line);

		for (int i = 0; i < (tokenlen); i++) {

			strcpy(in_line_cur_head,(char *)strtok(in_line_cur_head,(char *)splittoken[i]));

			cur_line_position = (char *)strtok(NULL,(char *)splittoken[i]);

			strcpy(in_line_cur_tail,cur_line_position);

			if (((long ) in_line_cur_tail - (long )in_line_cur_head) < 2) {

				cur_partial_token[i] = in_line_cur_tail[0];

			}
		}
	}

	if (tempcopy_in_line) free(tempcopy_in_line);

	if( in_line_cur_head) free( in_line_cur_head);

	if( in_line_cur_tail) free( in_line_cur_tail);

	if( return_line_cur_head) free( return_line_cur_head);
	strcpy(return_line_cur_head,final_line_cur_head);
	return return_line_cur_head;
}
int peoi_key_value_pair_extract(char *key,char *value,char *separator,char *delimit_custom_separator,char *in_line) {
	int success = 0;
	char *tempcopy_in_line;
	char *tempkey;
	char *tempvalue;
	tempcopy_in_line = (char *)malloc((strlen(in_line) * sizeof(char)) + 1);
	tempkey = (char *)malloc((strlen(in_line) * sizeof(char)) + 1);
	tempvalue = (char *)malloc((strlen(in_line) * sizeof(char)) + 1);
	strcpy(tempkey,"DEFAULT_KEY");
	strcpy(tempvalue,"DEFAULT_VALUE");
	strcpy(tempcopy_in_line,in_line);
	if (!strcmp(delimit_custom_separator," ")) {
		/*   FUNCTION CORE ACTION           ****  key and value are extracted by sscanf ******  */
		/*This asumes that the line being taken is of this format :
<KEYVALUE><CUSTOM SEPARATOR NOT SPACE><VALUE>(space here)<CUSTOM SEPARATOR NOT SPACE>*/
		sscanf(in_line,"%s %s",tempkey,tempvalue );
	}
	else {
		/*   FUNCTION CORE ACTION           **** temp keyand value are extracted by peoi_strtok ******  */
		strcpy(tempkey,peoi_strtok(tempcopy_in_line,delimit_custom_separator));
		if (tempcopy_in_line)  free(tempcopy_in_line);
		strcpy(tempvalue,peoi_strtok(NULL,delimit_custom_separator));
	}
	if (tempkey != NULL && tempvalue != NULL) {
		strcpy(key,tempkey);
		strcpy(value,tempvalue);
		success++;
	}
	else  {
		// failed
	}
	if (tempvalue) free(tempvalue);
	if (tempkey) free(tempkey);
	return success;
}
int peoi_token_replace(char *line,char **find_replace,char *newline) {
	//find_replace can be empty ; in that case, return just the copy
	if (find_replace[0] == NULL) {
		strcpy(newline,line);
	}
	else {
		int i = 0;
		long sepindex = 0L;
		char *needle = (char *)calloc(256,sizeof(char));
		while (strcmp(find_replace[i]," **  END OF LIST **")) {
#ifdef CONTROL_INSTRUCTIONS_FOR_DELETION
			/* anything in this _FOR_DELETION section will be removed automatically by cleaner*/
			printf(" iterate %i : in peoi_token_replace looking for %s ", 1+i, find_replace[i]);
			printf("\n >>>> found key %s at %i \n ",needle, i );
#endif //CONTROL_INSTRUCTIONS_FOR_DEL END
			i++;
		}
		strcpy(newline,line);
		// TODO : implement the toekn replacement
	}
	return 1;
}
FILE *peoi_load_textfile(char *name,unsigned int maxlineread, unsigned int seekoffset, char *fopen_type) {
	FILE *file;
	file = fopen((char *)name,fopen_type);
	if (file) {
		if (seekoffset > 0) {
			//  TODO  do somehting to advance file read pointer
		}
		return file;
	}
	else {
		return NULL;
	}
}
int peoi_load_file_for_token_insertion (char *name,char find_replace[],trackchain_struct *trace_execution) {
	char *buffr[1];
	char updated_str[8000];
	unsigned int maxlineread = 256;
	char *peoi_trace[1];
	//char array_of_str[8][256]= {{"1BLANK"},{"2BLANK"},{"3BLANK"},{"4BLANK"},{"BLANK"},{"BLANK"},{"BLANK"},{"BLANK"}};
	char **array_of_str;
	buffr[0] = (char *)malloc(1024* sizeof(char));
	buffr[0][0] = '\0';
	array_of_str = (char **)malloc(3 * sizeof(char));
	array_of_str[0] = (char *)malloc(256 * sizeof(char));
	array_of_str[1] = (char *)malloc(256 * sizeof(char));
	array_of_str[2] = (char *)malloc(256 * sizeof(char));
	strcpy(array_of_str[2],"2ARRAY CONTENT");
	peoi_trace[0] = (char *)malloc(1024* sizeof(char));
	trackchain_struct *curchaintrack;
	curchaintrack = (trackchain_struct *)malloc(sizeof(trackchain_struct));
	curchaintrack->trackMessage = (char *)malloc(maxlineread + 1);
	curchaintrack->child = (trackchain_struct *)malloc(sizeof(trackchain_struct));
	curchaintrack->child = NULL;
#ifdef CONTROL_INSTRUCTIONS_FOR_DELETION
	/* anything in this _FOR_DELETION section will be removed automatically by cleaner*/
	//printf("  in peoi_load_file_for_token_insertion   array of str using pointer arithmetic : %s \n", array_of_str+(2));
	//printf("  in peoi_load_file_for_token_insertion   array of str using [] : %s \n", array_of_str[2]);
#endif //CONTROL_INSTRUCTIONS_FOR_DEL END
	/*
 if (peoi_populate_token_replacement_array(array_of_str)) {
 }*/
	FILE *filehtml;
	filehtml = peoi_load_textfile(name,maxlineread * sizeof(char),0,"r");
	if (filehtml) {
		//fread((void *)buffr,sizeof(char),8000,filehtml);
		buffr[maxlineread + 1] = '\0';
		if (peoi_test_readlin(buffr,filehtml)) {
			// bad stuff

			//peoi_token_replace(buffr,array_of_str[0],updated_str);
			peoi_token_replace(buffr[0],array_of_str,updated_str) ;
		}
		// attache la chaine nouvelle à la chaine principale
		if (curchaintrack) trace_execution->child = curchaintrack;
	}
	else {
		strcpy(buffr[0],"FAILED ******************************************* \n");
	}
#ifdef CONTROL_INSTRUCTIONS_FOR_DELETION
	/* anything in this _FOR_DELETION section will be removed automatically by cleaner*/
	printf(" START LINE CONTENTS %s  END LINE CONTENTS  and token replaced \n", buffr[0]);
#endif //CONTROL_INSTRUCTIONS_FOR_DELEND
	return 1;
}
void printscriptchangecol(char *formname,char *insertword)
{int cc;cc=0;
        printf("<SCRIPT LANGUAGE=\"JavaScript\">\n");
printf(" <!--\n ");
printf("var iin=0; \n");
printf("var iout=0; \n");
printf("var ee='document.%s.anchortextend'; \n",formname);
printf("var e='document.%s.anchortextend'; \n",formname);
printf("var name=''; \n");
printf("var pastanchor='anchortextend'; \n");
printf("var pastanchorvalue='textend'; \n");
printf("var currentanchor='anchortextend'; \n");
printf("function chgcol2(anchname,numcol){ \n");
      printf(" var f = document.%s; \n",formname);
printf("currentanchor=anchname; \n");
printf("iin=numcol; \n");
printf("ancnum=numcol; \n");
if(cc)printf("if(geno>1)geno=0; \n");
printf("e = eval(\"document.%s.\" + anchname); \n",formname);
printf("ee = eval(\"document.%s.\" + pastanchor); \n",formname);
if(cc)printf("e.value='%s '+anchname; \n",insertword);
printf("e.value=dowhat+' '+anchname; \n");
printf("if(currentanchor!=pastanchor){ \n");
printf("e.className='btnclick'; \n");
printf("ee.className='btnhov'; \n");
printf("ee.value=pastanchor; \n");
printf("} \n");
if(!cc)printf("var name=' numcol='+numcol+' dowhat= '+dowhat+'/ currentanchor='+anchname+' pastanchor='+pastanchor+' value='+e.value+' type='+e.type+' class='+e.className+' pastanchor='+pastanchor+' numcol='+numcol;");
if(cc)printf("ee=e; \n");
printf("pastanchor=anchname; \n");
printf("document.%s.sanchor.value=numcol; \n",formname);
printf("if(iin>999 && confirm('%s '+anchname+' saction='+saction+'  ancnum='+ancnum+' numcol='+iin+' all')){iin=numcol; } \n",formname);
printf("if(iin>999 && confirm(name));\n");
printf("} \n");
printf("function setcol(anchname,numcol){ \n");
printf("currentanchor=anchname; \n");
printf("iin=numcol; \n");
printf("var msg = 'formname=%s numcol='+numcol+' anchname='+anchname;",formname);
printf("if(iin>999 && confirm(msg)){iin=numcol; } \n");
printf("var e = eval(\"document.%s.\" + anchname); \n",formname);
printf("e.value=dowhat+' '+anchname; \n");
printf("var dumvar=''; \n");
if(cc)printf("if(geno==1)geno='0';");
printf("e.className='btnclick'; \n");
printf("document.%s.sanchor.value=numcol; \n",formname);
printf("}\n");
printf("function removecol(pastanchor){ \n");
printf("var eee = eval(\"document.%s.\" + pastanchor); \n",formname);
printf("eee.value=dowhat+' '+pastanchor; \n");
printf("eee.className='btnclick'; \n");
printf("if(iin>999 && confirm(name)); \n");
printf("}");
printf(" // --></SCRIPT>\n");
}
void resizescript()
{int cc;
cc=0;
printf("  <SCRIPT LANGUAGE=\"JavaScript\">\n");
printf(" <!-- \n");
printf(" var i = 1; \n");
printf(" var u = 1; \n");
printf(" var g=0;\n");
printf(" var oldsize=3;\n");
printf(" var newsize=3;\n");
printf(" if(i>99)document.write('<BR> first cookie'+document.cookie);\n");
printf(" if((u=GetCookie('initSize')) && u>-1 && u<9)newsize=u;\n");
printf(" g=newsize-oldsize;\n");
printf("       if(g)fontSizer(g,'px');\n");
printf(" if(i>99)document.write('<BR>oldsize='+oldsize+' newsize='+newsize+' g='+g+' initSize='+initSize+'  pixelArray['+initSize+']='+pixelArray[initSize]);\n");
printf(" //  End -->\n");
printf("   </SCRIPT>\n");
}
int printverifyscript2()
{int cc,i;
cc=i=0;
printf("<SCRIPT LANGUAGE=\"JavaScript\"> \n");
printf(" function verifyrating() { \n");
printf(" var msg2 = 'Please, explain rating in comment!'; \n");
printf(" var kk=0;var good=1; \n");
printf(" var f = document.f2; \n");
		printf(" for (var i = 0; i<2; i++) { \n");
		printf(" var box = eval(\"f.newrate\"); \n");
		printf(" if(box[i].checked == 1 && f.comments.value.length<2)kk=1;}\n");
				printf(" if(kk>0){alert(msg2); return false; \n");
				printf(" } \n");
				printf(" return true;} \n");
				printf(" // --></SCRIPT>\n");
				return(i);
			}
using namespace std;
int poei_test_extract_1() {
	char *scanrul = "%*[a-zA-Z] %s";
			//char *scanrul = "/%,%/";
			char *trysscanf = "#WE ARE IN poei_test_extract_1 last";
			char firstel[25];
			char secondel[25];
			char *member1[25];
			char *member2[25];
			char sep[25];
			int judd = 0;
			char *tempscantarget = (char *)malloc(strlen(trysscanf) * sizeof(char) + 1);
			strcpy(tempscantarget,trysscanf);
			strcpy(firstel,strtok(tempscantarget,scanrul));
			strcpy(secondel,strtok(NULL,scanrul));
			member1[0] = (char *)malloc(256 * sizeof(char));
			//member1[1] = (char *)malloc(256 * sizeof(char));
			member1[1] =  peoi_malloc(member1[1],256 * sizeof(char));
			member2[0] = (char *)malloc(256 * sizeof(char));
			strcpy(member2[0],trysscanf);
			member2[1] = (char *)malloc(256 * sizeof(char));
			strcpy(member2[1]," ");
			if (peoi_test_key_value_extract_using_trailing_token(member1[0],member1[1],&member2[1],member2[0],256 * sizeof(char))) {
				printf("\n<<<<< in peoi_test_extract ___EXTRACT WITH TRAILING just returned  KEY %s for VALUE %s \n",member1[0],member1[1]);
			}
}


//MAIN FUNCTION
int main() {
void *l[4];
char *lk[16];
char **d;
int u;
void *library_handle;
const char *filenamer = "j.htmlfragment";
trackchain_struct *main_trace;
main_trace = (trackchain_struct *)malloc(sizeof(trackchain_struct));
/*
printscriptchangecol("%FORMNAME%","%INSERTWORD%");
resizescript();
u = printverifyscript2();*/
/*
library_handle = dlopen("libMP_cryptlib.so.0.08.0005",RTLD_DI_LMID);
// TODO implement the library !
if (library_handle == NULL) {
 dlsym(library_handle,"mp_getEncrypt");
}
*/
struct B {
char **j;
int z;
} b,e;
B *s;
d = (char **)calloc(2,sizeof(char));
d[0] = (char *)calloc(255,sizeof(char));
d[1] = (char *)calloc(255,sizeof(char));
/*if ((u = mp_getVersion(d[0]))) {
std::cout << (char *)d[0] << std::endl;
}*/
//l = calloc(2,sizeof(char));
l[0] = calloc(255,sizeof(char));
l[1] = calloc(255,sizeof(char));
l[2] = calloc(255,sizeof(char));
l[3] = NULL;
strcpy((char *)l[0],"Somestuff");
strcpy((char *)l[1],"Unwantedcrap");
lk[0] = (char *)malloc(255*sizeof(char));
lk[1] = (char *)malloc(255*sizeof(char));
lk[2] = (char *)malloc(255*sizeof(char));
lk[3] = (char *)malloc(255*sizeof(char));
lk[4] = (char *)malloc(255*sizeof(char));
lk[5] = (char *)malloc(255*sizeof(char));
lk[6] = (char *)malloc(255*sizeof(char));
lk[7] = NULL;
#ifdef CONTROL_INSTRUCTIONS_FOR_DELETION
// **********************************************     PEOI  STUFF
//char *trysscanf = "FIRSTELEMENT/%,%/SECONDELEMENT EDN";
//char *trysscanf = "        j.htmlfragment%/@/%FIRST ELEMENT/%,%/SECONDE LEMENTEDN /%,%/";
//char *trysscanf = "        j.htmlfragment%/@/%FIRST ELEMENT%/@/%SECONDE LEMENTEDN /%,%/";
//char *trysscanf = "        j.htmlfragment%/k/%FIRST ELEMENT%/k/%SECONDE LEMENTEDN /%,%/";
//char *trysscanf = "        j.htmlfragment/%?%/FIRST ELEMENT%/@/%SECONDE LEMENTEDN /%?%/";
//char *trysscanf = "j.htmlfragment/%?%/FIRST ELEMENT%/@/%SECONDE LEMENTEDN%/@/%LAST ELEMENT /%?%/";
char *trysscanf = "#The trailing set of symols which must have no spaces, will be hthe spearator for handling the specific line";
char *scanrul = "%*[a-zA-Z] %s";
//char *scanrul = "/%,%/";
char firstel[25];
char secondel[25];
char *member1[25];
char *member2[25];
char sep[25];
int judd = 0;
char *tempscantarget = (char *)malloc(strlen(trysscanf) * sizeof(char) + 1);
strcpy(tempscantarget,trysscanf);
strcpy(firstel,strtok(tempscantarget,scanrul));
strcpy(secondel,strtok(NULL,scanrul));
member1[0] = (char *)malloc(256 * sizeof(char));
//member1[1] = (char *)malloc(256 * sizeof(char));
member1[1] =  peoi_malloc(member1[1],256 * sizeof(char));
member2[0] = (char *)malloc(256 * sizeof(char));
strcpy(member2[0],trysscanf);
member2[1] = (char *)malloc(256 * sizeof(char));
strcpy(member2[1]," ");
/*member1 = strtok(tempscantarget,sep);
member2 = strtok(tempscantarget,sep);*/

judd
 = sscanf(trysscanf,scanrul,firstel,sep,secondel,member1);
//judd = sscanf(trysscanf,scanrul,firstel,sep,secondel);
printf("\n<<<<< SSCAND just returned %i elements : %s  and %s with sepr %s \n",judd,firstel,secondel,sep);
printf("\n<<<<< LAST SPACE just returned %i for %s \n",peoi_index_of_last_char_separator(trysscanf,html_token_separator.PEOI_HTML_CHAR_TOKEN_DELIMITER_CUSTOM_SEP),trysscanf);
printf("\n<<<<< LAST SPACE just returned %i for %s \n",99,trysscanf);
if (peoi_key_value_extract_using_trailing_token(member1[0],member1[1],&member2[1],member2[0],256 * sizeof(char))) {
printf("\n<<<<< EXTRACT WITH TRAILING just returned  KEY %s for VALUE %s \n",member1[0],member1[1]);
}
printf("\n<<<<< STRTOK just returned  HEAD %s for TOKEN %s \n",peoi_strtok(member1[1],"%/@/%"),"%/@/%");
printf("\n<<<<< NEXT CALL TO STRTOK just returned  HEAD %s for TOKEN %s \n",peoi_strtok(NULL,"%/@/%"),"%/@/%");
printf("\n<<<<< FINAL  TO STRTOK just returned  HEAD %s for TOKEN %s \n",peoi_strtok(NULL,"%/@/%"),"%/@/%");
printf("\n<<<<< STATIC TEST   %s \n",peoi_static("ONE                                             "));
printf("\n<<<<< STATIC TEST   %s \n",peoi_static("TWO               "));
printf("\n<<<<< STATIC TEST   %s \n",peoi_static("THREE               "));
printf("\n<<<<< STATIC TEST   %s \n",peoi_static("TFOUTH               "));
printf("\n<<<<< STATIC TEST   %s \n",peoi_static("FIVE               "));
/*if (peoi_load_file_for_token_insertion((char *)filenamer,(char *)"IN :/: OUT",main_trace)) {
}*/
trackchain_struct *mastertrack;
trackchain_struct *curtrack;
trackchain_struct *headofchaintrack;
trackchain_struct *chaintrack[1];
unsigned int maxtrackline = 256;
if(mastertrack->trackMessage == NULL) {
std::cout <<  "\n **  MASTER MESSAGE NULL  " << std::endl;
}
/*if (mastertrack[0]->child = (trackchain_struct *)peoi_malloc(mastertrack[0]->child,sizeof(trackchain_struct))) {
#ifdef CONTROL_INSTRUCTIONS_FOR_DELETION
// anything in this _FOR_DELETION section will be removed automatically by cleaner
printf("\n allocated  MASTER'S Child");
#endif //CONTROL_INSTRUCTIONS_FOR_DEL....END
}*/
std::cout <<  "\n **  MASTER MESSAGE SIZE  " << sizeof(mastertrack) << sizeof(mastertrack->trackMessage) << std::endl;
if (!peoi_malloc_trackstruct(&mastertrack,maxtrackline,chaintrack[0])) {
#ifdef CONTROL_INSTRUCTIONS_FOR_DELETION
 // anything in this _FOR_DELETION section will be removed automatically by cleaner
std::cout <<  "\n **  FAILED **  MALLOC TRACKSTRUCT " << std::endl;
#endif //CONTROL_INSTRUCTIONS_FOR_DELEND
}
else {
std::cout <<  "\n ** AFTER INSERTION MASTER MESSAGE SIZE  " << sizeof(mastertrack) << sizeof(mastertrack->trackMessage)  << std::endl;
//curtrack[0] = mastertrack[0]->child;
headofchaintrack = mastertrack;
curtrack = mastertrack;
if (headofchaintrack != NULL) {
strcpy(headofchaintrack->trackMessage,">YES MESSAGE IN HEAD TRACK<");
printf("\n HEAD CONTAINS was %s  and head's child is now %x (same as chaintrack %x) with size %i",mastertrack->trackMessage,mastertrack->child,chaintrack[0],sizeof(mastertrack->child));
if (!peoi_malloc_trackstruct(&curtrack,maxtrackline,chaintrack[0])) {
#ifdef CONTROL_INSTRUCTIONS_FOR_DELETION
 // anything in this _FOR_DELETION section will be removed automatically by cleaner
std::cout <<  "\n **  FAILED **  MALLOC TRACKSTRUCT " << std::endl;
#endif //CONTROL_INSTRUCTIONS_FOR_DELEND
}
strcpy(curtrack->trackMessage,">MORE USING CUTRACK IN HEAD TRACK<");
printf("\n CHAINED CONTAINS was %s  and head's child is now at %x (same as chaintrack %x) with size %i",curtrack->child->trackMessage,curtrack->child->child,chaintrack[0],sizeof(curtrack->child->child));
//curtrack[0] = chaintrack[0];
//chaintrack[0] = NULL;
if (!peoi_malloc_trackstruct(&curtrack,maxtrackline,chaintrack[0])) {
#ifdef CONTROL_INSTRUCTIONS_FOR_DELETION
 // anything in this _FOR_DELETION section will be removed automatically by cleaner
std::cout <<  "\n **  FAILED **  MALLOC TRACKSTRUCT " << std::endl;
#endif //CONTROL_INSTRUCTIONS_FOR_DELEND
}
strcpy(curtrack->trackMessage,">MORE SECOND***** CUTRACK IN HEAD TRACK<");
//curtrack[0] = chaintrack[0];
chaintrack[0] = NULL;
#ifdef CONTROL_INSTRUCTIONS_FOR_DELETION
/* anything in this _FOR_DELETION section will be removed automatically by cleaner*/
printf("\n CHAINED CONTAINS was %s  and head's child is now at %x (same as chaintrack %x) with size %i",curtrack->child->trackMessage,curtrack->child,chaintrack[0],sizeof(curtrack->child));
printf("\n MORE CHAINED CONTAINS was %s  and head's child is now at %x (same as chaintrack %x) with size %i",curtrack->child->child->trackMessage,curtrack->child->child,chaintrack[0],sizeof(curtrack->child->child));
#endif //CONTROL_INSTRUCTIONS_FOR_DELEND
FILE *substitutionfile;
substitutionfile = peoi_load_textfile("j.html",256,0,"r") ;
char *jii[1];
jii[0] = (char *)malloc(1024 * sizeof(char));
if (substitutionfile) {
printf("\n  FILE OPEN WORKS");
while (!peoi_test_iseof(substitutionfile)) {

//jii[0] = fgets(jii[0],400,substitutionfile);
jii[0] = peoi_test_readlin(jii,substitutionfile);
printf("\n  FILE OPEN EXTRACTED %s",jii[0]);
}
}
if (peoi_populate_token_replacement_array(lk)) {
printf("\n POPULATE JUST CAME BAK WITH %s",lk[0]);
 }
/*
if (peoi_readline(jii,"j
html",400,substitutionfile) != NULL) {
}*/
if( jii[0]) free( jii[0]);
}
else {
cout << "\n  BAD NEWS" << endl;
}
//cout << "\n" << headofchaintrack->trackMessage << endl;
}
if(headofchaintrack) free(headofchaintrack);
#endif  // CONTROL_INSTRUCTIONS_FOR_DELEND
if (poei_test_extract_1()) {
}
// **********************************************     PEOI  STUFF   END ****
b.j = (char **)l;
e.j = (char **)l;
//setenv("LD_LIBRARY_PATH","/home/marc/workspace/BestTry/Release:$LD_LIBRARY_PATH",)
//e.z = mp_getVersion(d);
free(d);
d = (char **)calloc(2,sizeof(char));
d[0] = (char *)calloc(255,sizeof(char));
d[1] = (char *)calloc(255,sizeof(char));
strcat(d[0],"Long words reversed");
//e.z = mp_getEncrypt(d[0]);
strcpy(e.j[1],"Morecrap");
s->j = (char **)l;
strcpy((char *)l[2],"After insert");
cout << "[GB_en]Hello World " << d[0] << " returned int : " << e.z << "detailed version :" <<  d[1] << b.j[0] << " " << e.j[1] << " " << s->j[2] << endl; // prints [GB_en]Hello World
    cout << "bool:\t\t" << sizeof(bool) << " bytes" << endl;
    cout << "char:\t\t" << sizeof(char) << " bytes" << endl;
    cout << "wchar_t:\t" << sizeof(wchar_t) << " bytes" << endl;
    cout << "short:\t\t" << sizeof(short) << " bytes" << endl;
    cout << "int:\t\t" << sizeof(int) << " bytes" << endl;
    cout << "long:\t\t" << sizeof(long) << " bytes" << endl;
    cout << "float:\t\t" << sizeof(float) << " bytes" << endl;
    cout << "double:\t\t" << sizeof(double) << " bytes" << endl;
   // using namespace mp_crypt_h;
  //  cout << "sctruct:\t\t" << mp_crypt_h::mp_crypt_types.MP_CRYPTTYPE_REVERSE   << " value" << endl;
  //  cout << "summ:\t\t" << mp_setEncryptType((int)mp_crypt_h::mp_crypt_types.MP_CRYPTTYPE_REVERSE)  << " value" << endl;
  //  cout << "summ should faill (9999):\t\t" << mp_setEncryptType(31)  << " value" << endl;
   cout << "long double:\t" << sizeof(long double) << " bytes" << endl;
// mp_setEncryptType
/*Free the memory tha was calloc'd'*/
free(d);
free(l[0]);free(l[1]);free(l[2]);free(l[3]);
return 0;
}


